package reflect;

import reflect.annotations.AutoRunMethod;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;

public class Test2 {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, InvocationTargetException {
        Person p=new Person();
        List<Integer> list=new ArrayList<>();
        Class cls1=p.getClass();
        Object obj=cls1.newInstance();
        Method[] methods=cls1.getMethods();

        for(Method method : methods) {

            if(method.getModifiers()== Modifier.PUBLIC &&
            method.getParameterCount()==0) {
                System.out.println(method.getName() );
                method.invoke(obj);
            }
        }

        for(Method method : methods) {
            boolean mark=method.isAnnotationPresent(AutoRunMethod.class);
            if(mark) {
                System.out.println(method.getName() );
                method.invoke(obj);
            }
        }
    }
}
